package com.java.basis.string;

import org.junit.Test;

import java.text.DecimalFormat;
import java.util.Date;

/**
 * @author wangning
 * @create 2021-04-25 11:22
 */
public class TestStringFormat02 {

	//可以用来动态补零
	@Test
	public void formatString() {
		int i = 1100;
		String s = "012";
		String format = new DecimalFormat("0000").format(Integer.parseInt(s));
		String format1 = new DecimalFormat("0000").format(9);
		System.out.println("format = " + format);
		String str = String.format("Hi, %s", "林计钦");
		System.out.println("String.format = " + str);
		str = String.format("50元的书打8.5折扣是：%f 元%n", 50*0.85);
		System.out.println(str);
		System.out.printf("3>7的结果是：%b %n", 3>7);
		Date date = new Date();
		System.out.printf("全部日期和时间信息：%tc%n", date);//格式化输出日期或时间
		System.out.printf("年-月-日格式：%tF%n", date);
		System.out.printf("月/日/年格式：%tD%n", date);
		System.out.printf("HH:MM:SS PM格式(12时制)：%tr%n", date);
		System.out.printf("HH:MM:SS格式(24时制)：%tT%n", date);
		System.out.printf("HH:MM格式(24时制)：%tR%n", date);
	}
}
